﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HCQ2_IBLL;
using HCQ2_Model.VR;
using HCQ2_Model.VR.Params;
using HCQ2_Model.VR.Model;
using System.Web;

namespace HCQ2_BLL
{
    public partial class T_VRGoldLogBLL: IT_VRGoldLogBLL
    {
        /// <summary>
        ///  获取金币日志列表
        /// </summary>
        /// <param name="param">查询参数</param>
        /// <param name="total">返回记录总数</param>
        /// <returns></returns>
        public List<T_VRGoldLogModel> GetGoldList(GoldParam param, out int total)
        {
            return DBSession.IT_VRGoldLogDAL.GetGoldList(param,out total);
        }
        /// <summary>
        /// 获取销售明细
        /// </summary>
        /// <param name="param"></param>
        /// <param name="total"></param>
        /// <returns></returns>
        public List<T_VRSellGoldLogModel> GetSellGoldList(SellGoldParam param, out int total)
        {
            return DBSession.IT_VRGoldLogDAL.GetSellGoldList(param, out total);
        }
        /// <summary>
        ///  获取销售额列表
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public List<SaleMoneyResult> GetSaleList(SaleMoneyParam param)
        {
            List < SaleMoneyResult > list= DBSession.IT_VRGoldLogDAL.GetSaleList(param);
            list.ForEach(o =>
            {
                var query = DBSession.IT_DocBagFileRecordDAL.Select(s => s.file_id == o.file_id);
                if(query!=null && query.Count > 0)
                {
                    List<PicModel> pic = new List<PicModel>();
                    query.ForEach(s => {
                        if (!string.IsNullOrEmpty(s.file_url))
                            pic.Add(new PicModel { file_type = s.file_type, file_url = s.file_url.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/"))) });
                    });
                    o.pic = pic;
                }
            });
            return list;
        }
        /// <summary>
        ///  获取合伙人申请
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public List<FounderList> GetFounderList(FounderParam param, int user_id)
        {
            var list= DBSession.IT_VRGoldLogDAL.GetFounderList(param, user_id);
            list?.ForEach(s =>
            {
                if (s.du_friend > 0)
                    //好友
                    s.du_friend = 1;
                else
                {
                    if (s.du_friend2 > 0)
                        s.du_friend = 2;
                    else if (s.du_friend3 > 0)
                        s.du_friend = 3;
                    else
                        s.du_friend = 100;
                }
                if (!string.IsNullOrEmpty(s.user_img) && s.user_img.IndexOf("http") < 0)
                    s.user_img = s.user_img.Replace("~", HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, HttpContext.Current.Request.Url.AbsoluteUri.IndexOf("/api/")));
            });
            return list;
        }
    }
}